package com.javasm.crm.service.impl.productimpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javasm.crm.domin.criteria.BrandCriteria;
import com.javasm.crm.domin.entity.productEntity.Brand;
import com.javasm.crm.domin.entity.productEntity.Color;
import com.javasm.crm.domin.entity.productEntity.GoodsVo;
import com.javasm.crm.mapper.goodsmapper.BrandMapper;
import com.javasm.crm.mapper.goodsmapper.ColorMapper;
import com.javasm.crm.service.productservice.BrandService;
import com.javasm.crm.service.productservice.ColorService;
import com.javasm.crm.utils.page.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @Author：zhangyang
 * @Version：1.0
 * @Date：2021/7/13-10:41
 * @desp:
 * @since:
 */
@Service
@Transactional
public class BrandServiceImpl extends ServiceImpl<BrandMapper,Brand> implements BrandService {
    @Autowired
    BrandMapper brandMapper;
    @Override
    public List<Brand> getAllBrands() {
        return brandMapper.selectList(null);
    }

    @Override
    public PageResult<Brand> searchPageByCriteria(BrandCriteria brandCriteria) {
        Integer currentPage = brandCriteria.getCurrentPage();

        Integer pageSize = brandCriteria.getPageSize();
        if (StringUtils.isEmpty(currentPage)) {
            currentPage=1;
        }
        if (StringUtils.isEmpty(pageSize)) {
            pageSize=5;
        }
        System.out.println("brandCriteria.getBrandName:"+brandCriteria.getBrandName());
        QueryWrapper<Brand> exampleQueryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(brandCriteria.getBrandName())){
            exampleQueryWrapper.like("brand_name",brandCriteria.getBrandName());
        }
        Page<Brand> examplePage = new Page<>(currentPage, pageSize);
        List<Brand> queryall = brandMapper.queryall(examplePage, exampleQueryWrapper);

        return new PageResult<Brand>(examplePage.getTotal(), queryall);
    }

    @Override
    public int deleteById(Serializable id) {
        return brandMapper.deleteById(id);
    }

    @Override
    public int addBrand(Brand brand) {
        return brandMapper.insert(brand);
    }

    @Override
    public int update(Brand t) {
        return brandMapper.updateById(t);
    }
//    @Autowired
//    ColorMapper colorMapper;
//    @Override
//    public List<Color> getAllColors() {
//        return colorMapper.selectList(null);
//    }
}
